home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / vacuum.zip / VACUUM.ASM < prev    next >
Assembly Source File  |  1987-01-24  |  7KB  |  157 lines

  1. ;VACUUM.ASM -- program to direct read all sectors on a floppy
  2. ;in drive B, writing 90 sectors per file to a series of output
  3. ;files, 1.FIX, 2.FIX, etc., on the default drive.  Sectors
  4. ;are processed in order of logical number.  Sectors consisting
  5. ;entirely of the same byte are not included in the output.
  6. ;
  7. cr        equ       0dh
  8. lf        equ       0ah
  9. ;
  10. cseg      segment   para     public     'CODE'
  11.           org       100h
  12.           assume cs:cseg, ds:cseg,es:cseg,ss:cseg
  13. vacuum    proc      near
  14.           jmp       start
  15. ;
  16. mess1     db        7,'THE VACUUM CLEANER Ver. 1.0  1/24/87',cr,lf
  17.           db        ' by D. Seidman',cr,lf
  18.           db        ' Damaged disk in drive B. Output '
  19.           db        'to default drive.',cr,lf,' Press any'
  20.           db        ' alpha key to start.',cr,lf,'$'
  21. handle    dw        ?
  22. filename  db        '1.FIX',0
  23. mess2     db        7,'File creation failure. Aborting.','$'
  24. mess3     db        7,'Insert another disk in default drive,',cr,lf
  25.           db        'then press any alpha key.',cr,lf,'$'
  26. sectot    dw        0
  27. sector    db        512 dup (?)
  28. divider   db        cr,lf,'END SECTOR '
  29. secno     db        4 dup (?)
  30.           db        cr,lf,'$'
  31. secount   db        0
  32. ;
  33. start:    mov       dx, offset mess1    ;intro message
  34.           mov       ah, 9               ;output string
  35.           int       21h
  36.           mov       ah, 0ch
  37.           mov       al, 8               ;wait for keypress
  38.           int       21h
  39.           call      open
  40. again:    inc       sectot              ;sector to read
  41.           cmp       sectot, 721
  42.           je        done
  43.           mov       al,1                ;read drive B. Or 0 for drive A,etc.
  44.           mov       cx,1                ;read one sector only
  45.           mov       dx, sectot          ;this sector
  46.           mov       bx, offset sector   ;into here
  47.           int       25h                 ;sector read
  48.           add       sp, 2               ;clean up after the read
  49.           jc        again               ;if error, skip over it
  50.           cld
  51.           mov       al, sector          ;get first char of sector
  52.           mov       cx, 512             ;check a whole sector
  53.           mov       di, offset sector   ;start address
  54. repe      scasb                         ;check for equal bytes
  55.           je        again               ;if equal at end, no good
  56.                                         ;now save it
  57. ;this tries to write the number in hex
  58.           lea       di, secno           ;where to put number
  59.           mov       ax, sectot          ;for call
  60.           call      conv_word
  61. ;end attempt
  62.           mov       ah, 40h             ;write file
  63.           mov       bx, handle
  64.           mov       cx, 531             ;size of sector plus divider
  65.           mov       dx, offset sector   ;what to write
  66.           int       21h                 ;write it
  67. ;assuming no error here
  68.           inc       secount             ;sectors in this file
  69.           cmp       secount, 90         ;90 sectors per file
  70.           jne       again               ;recycle is not done
  71.           mov       ah, 3eh             ;close file
  72.           mov       bx, handle          ;should be unnecessary
  73.           int       21h
  74.           mov       secount, 0          ;reset counter
  75.           cmp       sectot, 720         ; don't open another file
  76.                                         ;if finished.
  77.           je        done
  78.           call      open
  79.           jmp       again
  80. done:     int       20h
  81. vacuum    endp
  82. ;
  83. open      proc      near
  84. ;opens files, dies with message if error
  85. ;check to see if enough space, assuming 512 byte sectors
  86. ;and two sectors per cluster, which is wrong for hard disks.
  87.           mov       ah, 36h             ;call for free disk space
  88.           mov       dl, 0               ;using default drive
  89.           int       21h
  90.           cmp       bx, 48              ; 48 clusters needed for a file
  91.           ja        enough
  92.           mov       dx, offset mess3    ;need another disk
  93.           mov       ah, 9
  94.           int       21h
  95.           mov       ah, 0ch             ;wait for keypress
  96.           mov       al, 08h
  97.           int       21h
  98. enough:   mov       ah, 3ch
  99.           xor       cx, cx
  100.           mov       dx, offset filename
  101.           int       21h
  102.           jnc       opened
  103.           mov       dx, offset mess2
  104.           mov       ah, 9
  105.           int       21h
  106.           int       20h                 ;quit if error
  107. opened:   mov       handle,ax
  108.           inc       filename            ;that is supposed to increment
  109.                                         ;the first byte of thefilename
  110.           ret
  111. open      endp
  112.  
  113. conv_word proc      near                ;convert 16-bit binary word
  114.                                         ;  to hex ASCII
  115.                                         ;call with AX = binary value
  116.                                         ;          DI =addr to store
  117.                                         ;returns AX,DI,CX destroyed
  118.                                         ;(c) 1984 by Ray Duncan.
  119.                                         ;Published in Advanced MS-DOS
  120.           push      ax
  121.           mov       al,ah
  122.           call      conv_byte           ;convert upper byte
  123.           pop       ax
  124.           call      conv_byte           ;convert lower byte
  125.           ret
  126. conv_word endp
  127.  
  128. conv_byte proc      near                ;convert binary byte to hex ASCII
  129.                                         ;call with AL = binary value
  130.                                         ;       DI = addr to store string
  131.                                         ;returns AX, DI, CX modified
  132.           sub       ah,ah               ;clear upper byte
  133.           mov       cl, 16
  134.           div       cl                  ;divide binary data by 16
  135.           call      ascii               ;quotient becomes the first
  136.           stosb                         ;ascii character
  137.           mov       al,ah
  138.           call      ascii               ;remainder becomes the
  139.           stosb                         ;second ASCII character
  140.           ret
  141. conv_byte endp
  142.  
  143. ascii     proc      near                ;convert value 0-0FH in AL
  144.           add       al, '0'             ;into a "hex ascii" character
  145.           cmp       al, '9'
  146.           jle       ascii2              ;jump if in range 0-9
  147.           add       al,'A'-'9'-1        ;offset into range A-F
  148. ascii2:   ret                           ;return ASCII char in AL
  149. ascii     endp
  150. ;
  151. cseg      ends
  152.           end       vacuum
  153.  
  154.  
  155.  
  156.  
  157.